<?php
/**
 * Created by PhpStorm.
 * User: hebidu
 * Date: 15/7/24
 * Time: 15:44
 */

namespace Api\Controller;

use Think\Controller;

/**
 * 头像获取接口
 * Class AvatarController
 * @package Api\Controller
 */
class AvatarController extends Controller
{

    protected $default = "iVBORw0KGgoAAAANSUhEUgAAAKAAAACgCAIAAAAErfB6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAxJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MTk1RDAzRkEyOUQ0MTFFNThENTc5RkQ5MEIwQkVDRTIiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MTk1RDAzRjkyOUQ0MTFFNThENTc5RkQ5MEIwQkVDRTIiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiBNYWNpbnRvc2giPiA8eG1wTU06RGVyaXZ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4CTTc2Zr5ACdDN3WgJM7ZyZmXn58mUsFpPQVo7IsUTZKLGWLJr55OHh4e7ubsVvkDOyQ/lHgAEAX2SabPPS8WgAAAAASUVORK5CYII=";

    public function index()
    {

        if (IS_GET) {
            $uid = I('get.uid', 0);

            $Picture = D('UserPicture');
            $result = $Picture->where(array('uid' => $uid, 'type' => 'avatar'))->order('create_time desc')->find();

            if ($result === false || empty($result['imgurl'])) {
                header('Content-type: image/png');
                echo base64_decode($this->default);
                exit();
            }

            $imgurl = $result['imgurl'];

            $image = @file_get_contents($imgurl);
            if ($image == false) {
                header('Content-type: image/png');
                echo base64_decode($this->default);
                exit();
            }
            header('Content-type: image/'.$result['ext']);
            echo $image;
            exit();
        }

    }

}